/*
 * TimePoint.h
 *
 *  Created on: 2016年4月19日
 *      Author: terry
 */

#ifndef TIMEPOINT_H_
#define TIMEPOINT_H_

#include "BasicType.h"
#include <stdlib.h>



namespace util
{

class TimePoint
{
public:
	TimePoint():
		m_clock(),
		m_pts()
	{
	}

	virtual ~TimePoint()
	{
	}

	TimePoint(int64_t clock, int64_t pts):
		m_clock(clock),
		m_pts(pts)
	{
	}


	void reset(int64_t clock, int64_t pts)
	{
	    m_pts = pts;
	    m_clock = clock;
	}

	void reset(const TimePoint& tp)
	{
		m_pts = tp.m_pts;
		m_clock = tp.m_clock;
	}

	void reset()
	{
		m_pts = 0;
		m_clock = 0;
	}

	bool isSet() const
	{
		return (m_clock != 0);
	}

	int64_t getOffset(int64_t clock, int64_t pts) const
	{
		return (m_pts - pts) - (m_clock - clock);
	}

	int64_t getOffset(const TimePoint& pt) const
	{
		return getOffset(pt.m_clock, pt.m_pts);
	}

	int64_t getOffset(int64_t clock, int64_t pts, float scale) const
	{
		return (int64_t)((m_pts - pts) / scale) - (m_clock - clock);
	}

	int64_t getOffset(const TimePoint& pt, float scale) const
	{
		return getOffset(pt.m_clock, pt.m_pts, scale);
	}

	int64_t getClockDiff(const TimePoint& pt) const
	{
		return getClockDiff(pt.m_clock);
	}

	int64_t getClockDiff(int64_t clock) const
	{
		return abs((int)(m_clock - clock));
	}


public:
	int64_t m_clock;
	int64_t m_pts;

};


} /* namespace av */

#endif /* TIMEPOINT_H_ */
